// import Cookies from "js-cookie";

const TokenKey = "Admin-Token";
const userKey = "User-Number"

export function getToken() {
	return uni.getStorageSync(userKey);
}

export function setToken(token) {
	uni.setStorageSync(TokenKey, token)
}

export function removeToken() {
	uni.removeStorageSync(TokenKey)
}
export function getUserNum() {
	return uni.getStorageSync(userKey);
}

export function setUserNum(userNumber) {
	uni.setStorageSync(userKey, userNumber)
}

export function removeUserNum() {
	uni.removeStorageSync(userKey)
}

const root = "Authorization";

export function getTokenSync() {
  const nowTime = Date.parse(new Date()) / 1000;
  const rootValue = uni.getStorageSync(root).split("@");
  const time = rootValue[1];
  if (nowTime > time) {
    removeToken();
    return undefined;
  }
  return rootValue[0];
  // const token = uni.getStorageSync(Authorization).split('@');
  // token = token[0]
  // return token;
}
/**
 * 设置定时token
 * @param {*} token token 时间
 * @param {*} date token 过期时间
 */
export function setTokenSync(token, date) {
  if (date) {
    const time = Date.parse(new Date()) / 1000;
    const rootTime = token + "@" + (date + time);
    return uni.setStorageSync(root, rootTime);
  }
  return uni.setStorageSync(root, token);
}

export function removeTokenSync() {
  return uni.removeStorageSync(root);
}
